<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>03.get请求传递参数</title>
  </head>

  <body>
    <p>姓名:<input type="text" id="name"></p>
    <p>密码:<input type="text" id="pw"></p>
    <p><button id="btn">提交</button></p>
  </body>
  <script>
    let id = document.querySelector("#name");
    let pw = document.querySelector("#pw");
    let btn = document.querySelector("#btn");
    btn.addEventListener("click", () => {
      let name = id.value;
      pw = pw.value;
      const xhr = new XMLHttpRequest();
      // xhr.open('get', 'http://localhost:3000/deliverData?name=' + name + '&password=' + pw);
      //get方式请求传递参数需要自己拼接
      let param = "name=" + name + "&password=" + pw;
      xhr.open('get', 'http://localhost:3000/deliverData?' + param);
      xhr.send();
      xhr.onload = function () {
        console.log(xhr.response);
      }
    })
  </script>

</html>